package com.ce.pms.report.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ce.pms.report.dao.IReportDao;
import com.ce.pms.report.queryvo.AlreadyBuildAndItemQueryVO;
import com.ce.pms.report.vo.AlreadyBuildAndItemReportVO;
import com.ce.report.entity.CEReportDataSet;
import com.ce.report.exception.CEReportException;
import com.ce.report.service.ICEReportDataSetService;
import com.ce.report.vo.ReportsQueryBaseVo;
import com.ce.util.BlankUtil;
import com.ce.util.DateUtil;

/**
 *
 * 功能描述：财务已收款分栋分项汇总表 Service
 * <p>
 * 版权所有：中企动力
 * <p>
 * 未经本公司许可，不得以任何方式复制或使用本程序任何部分
 *
 * @author 黄彦军 Created on 2008-10-28 Edit author: Edit on: 修改原因:
 */
public class AlreadyBuildAndItemService implements ICEReportDataSetService {

	private IReportDao reportDao;

	public CEReportDataSet getReportDataSet(ReportsQueryBaseVo arg0)throws CEReportException {
		AlreadyBuildAndItemQueryVO queryVO = (AlreadyBuildAndItemQueryVO) arg0;

		return new CEReportDataSet(getData(queryVO),getHeadInfo(queryVO));
	}

	/**
	 * 功能描述:获取数据  <br>
	 * @param queryVO
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-11-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private List<AlreadyBuildAndItemReportVO> getData(AlreadyBuildAndItemQueryVO queryVO) {
		String precinct = queryVO.getPrecinct() ;
		int subentry = queryVO.getSubentry();
		String computeMonth = DateUtil.convertDateToStr(queryVO.getComputeMonth(), "yyyyMM") ;
		Object[] obj = new Object[] { subentry, subentry, subentry, subentry,
				subentry, subentry, subentry, subentry, subentry, computeMonth,
				precinct };

		List<Object[]> temp = reportDao.getDataList("alreadyBuildAndItem", obj);
		List<AlreadyBuildAndItemReportVO> list = arrayToVO(temp);

		return list;
	}

	/**
	 * 功能描述:已收款分栋分项汇总对象数组 转为 VO 数组 <br>
	 *
	 * @param temp
	 * @return Create author:黄彦军 <br>
	 *         Create on:2008-11-7 <br>
	 *         Edit author: <br>
	 *         Edit on: <br>
	 *         Why: <br>
	 */
	private List<AlreadyBuildAndItemReportVO> arrayToVO(
			List<Object[]> temp) {
		if (BlankUtil.isBlank(temp))
			return null;
		List<AlreadyBuildAndItemReportVO> list = new ArrayList<AlreadyBuildAndItemReportVO>();
		for (Object[] obj : temp) {
			AlreadyBuildAndItemReportVO reportVO = new AlreadyBuildAndItemReportVO();
			reportVO.setCompanyName((String) obj[0]);// 物业公司名称
			reportVO.setBuildingName((String) obj[1]);// 大楼名称
			reportVO.setActualPay((BigDecimal) obj[2]);// 实收金额
			reportVO.setActualThis((BigDecimal) obj[3]);// 实收本月
			reportVO.setActualBefore((BigDecimal) obj[4]);// 实收往月
			reportVO.setLatefee((BigDecimal) obj[5]);// 滞纳金
			reportVO.setOverheadExpenses((BigDecimal) obj[6]);// 管理费
			reportVO.setOnticUpkeep((BigDecimal) obj[7]);// 本体维修金
			reportVO.setElectricityPay((BigDecimal) obj[8]);// 电费
			reportVO.setWaterPay((BigDecimal) obj[9]);// 水费
			reportVO.setSewagePay((BigDecimal) obj[10]);// 污水处理费
			reportVO.setGarbagePay((BigDecimal) obj[11]);// 垃圾处理费
			reportVO.setUpkeepPay((BigDecimal) obj[12]);// 维修费
			reportVO.setAdjustSum((BigDecimal) obj[13]);// 调整费用合计
			reportVO.setDerateSum((BigDecimal) obj[14]);// 减免费用合计

			list.add(reportVO);
		}
		return list;
	}

	/**
	 * 功能描述:获取头信息  <br>
	 * @param queryVO
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-11-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private Map<String,Object> getHeadInfo(AlreadyBuildAndItemQueryVO queryVO){

		Map<String, Object> map =new HashMap<String, Object>();
		String computeMonth = DateUtil.convertDateToStr(queryVO.getComputeMonth(), "yyyyMM");
		map.put("reportHeadStr", "计费月份:"+computeMonth);
		map.put("printDate", new Date());
		String subentry = "";
		if(queryVO.getSubentry() == 1){
			subentry="本月费用";
		}else if(queryVO.getSubentry() == 2){
			subentry="往月欠款";
		}else{
			subentry="本月费用 + 往月欠款";
		}
		map.put("subentry", subentry);
		return map;
	}

	public void setReportDao(IReportDao reportDao) {
		this.reportDao = reportDao;
	}

}
